import {RectNode, RectNodeModel, h} from "@logicflow/core";
import {setCommonStyle} from "@/components/design/common/js/tool.js";

class BetweenModel extends RectNodeModel {

  initNodeData(data) {
    super.initNodeData(data);
    this.width = 100;
    this.height = 80;
    this.radius = 5;
  }
  getNodeStyle() {
    return setCommonStyle(super.getNodeStyle(), this.properties, "node");
  }
}

class BetweenView extends RectNode {

  getLabelShape() {
    const {model} = this.props;
    const {x, y, width, height, text} = model;
    const style = model.getNodeStyle();

    // 创建一个包含图标和文本的容器
    return h(
        'svg',
        {
          x: x - width / 2 + 2,
          y: y - height / 2 + 2,
          width: 25,
          height: 25,
          viewBox: '0 0 1024 1024',
        },
        [
          h('path', {
            d: 'M135.314286 877.714286h735.085714v-208.457143s-69.485714-128-215.771429-160.914286h-285.257142c-135.314286 40.228571-237.714286 179.2-237.714286 179.2l3.657143 190.171429z',
            fill: '#FCF7EC'
          }),
          h('path', {
            d: 'M676.571429 457.142857H362.057143c-149.942857 47.542857-266.971429 204.8-266.971429 204.8v256H914.285714v-277.942857c3.657143 0-73.142857-138.971429-237.714285-182.857143zM863.085714 877.714286H138.971429v-190.171429s102.4-142.628571 237.714285-179.2h285.257143c146.285714 36.571429 204.8 153.6 204.8 153.6V877.714286h-3.657143z',
            fill: style.stroke ? style.stroke : '#2B2F36',
          }),
          h('path', {
            d: 'M650.971429 446.171429c36.571429-36.571429 58.514286-84.114286 58.514285-138.971429 0-21.942857-3.657143-43.885714-10.971428-62.171429v-7.314285c-29.257143-73.142857-98.742857-128-182.857143-128-109.714286 0-197.485714 87.771429-197.485714 197.485714 0 58.514286 25.6 113.371429 69.485714 149.942857-14.628571 14.628571-25.6 25.6-25.6 51.2 0 32.914286 0 54.857143 43.885714 98.742857s201.142857 40.228571 245.028572 0c40.228571-40.228571 36.571429-84.114286 36.571428-113.371428-3.657143-18.285714-21.942857-40.228571-36.571428-47.542857zM354.742857 307.2z m288.914286 182.857143v14.628571c0 7.314286 0 25.6-3.657143 36.571429s-14.628571 25.6-18.285714 29.257143l-3.657143 3.657143c-3.657143 3.657143-3.657143 3.657143-7.314286 3.657142s-14.628571 7.314286-32.914286 10.971429c-3.657143 0-10.971429 3.657143-14.628571 3.657143-18.285714 3.657143-43.885714 3.657143-65.828571 0-7.314286 0-14.628571 0-21.942858-3.657143-7.314286 0-10.971429-3.657143-14.628571-3.657143-14.628571-3.657143-18.285714-7.314286-21.942857-7.314286l-3.657143-3.657142c-7.314286-3.657143-14.628571-14.628571-14.628571-14.628572l-3.657143-3.657143c-3.657143-7.314286-14.628571-18.285714-14.628572-21.942857s-3.657143-18.285714-3.657143-25.6v-3.657143s0-7.314286 3.657143-14.628571c0-3.657143 3.657143-7.314286 3.657143-7.314286l3.657143-3.657143c29.257143 18.285714 65.828571 29.257143 102.4 29.257143 43.885714 0 80.457143-14.628571 113.371429-36.571428 3.657143 0 3.657143 3.657143 7.314285 7.314285l10.971429 10.971429c0-3.657143 0-3.657143 0 0z m-7.314286-95.085714c-7.314286 10.971429-14.628571 21.942857-21.942857 29.257142-25.6 21.942857-62.171429 40.228571-102.4 40.228572-25.6 0-51.2-7.314286-73.142857-18.285714l14.628571-14.628572s-25.6-10.971429-32.914285-14.628571c-3.657143 0-7.314286-3.657143-14.628572-10.971429-7.314286-3.657143-10.971429-10.971429-18.285714-14.628571-3.657143-7.314286-10.971429-10.971429-14.628572-14.628572-3.657143-3.657143-7.314286-7.314286-7.314285-10.971428v-7.314286s47.542857-40.228571 87.771428-47.542857c40.228571-10.971429 58.514286-3.657143 58.514286-3.657143s7.314286 3.657143 18.285714 3.657143c10.971429 3.657143 25.6 3.657143 36.571429 3.657143s21.942857 0 36.571428-3.657143c7.314286 0 10.971429-3.657143 18.285715-3.657143s10.971429-3.657143 14.628571-3.657143c14.628571-3.657143 18.285714-7.314286 18.285714-7.314286s0 21.942857-3.657142 36.571429c0 7.314286-3.657143 18.285714-7.314286 29.257143 3.657143 10.971429-3.657143 21.942857-7.314286 32.914286zM288.914286 749.714286h54.857143V877.714286H288.914286zM658.285714 749.714286h54.857143V877.714286H658.285714z',
            fill: style.stroke ? style.stroke : '#2B2F36',
          }),
          h('path', {
            d: 'M365.714286 358.4s47.542857-40.228571 87.771428-47.542857c40.228571-10.971429 58.514286-3.657143 58.514286-3.657143s32.914286 7.314286 54.857143 7.314286 51.2-3.657143 69.485714-10.971429l18.285714-7.314286s3.657143 21.942857 0 40.228572c-3.657143 14.628571-10.971429 40.228571-21.942857 58.514286-14.628571 21.942857-29.257143 40.228571-40.228571 51.2 0 0 21.942857 14.628571 25.6 18.285714 0 0 7.314286 3.657143 14.628571 10.971428 7.314286 7.314286 10.971429 10.971429 10.971429 14.628572v14.628571c0 7.314286 0 25.6-3.657143 36.571429s-14.628571 25.6-18.285714 29.257143l-10.971429 10.971428c-3.657143 3.657143-25.6 10.971429-47.542857 14.628572-21.942857 3.657143-62.171429 3.657143-87.771429 0-25.6-7.314286-32.914286-10.971429-36.571428-10.971429s-18.285714-18.285714-18.285714-18.285714-14.628571-18.285714-18.285715-25.6-3.657143-29.257143-3.657143-29.257143-3.657143-14.628571 7.314286-25.6 32.914286-43.885714 32.914286-43.885714-7.314286-7.314286-21.942857-14.628572c-3.657143-3.657143-21.942857-18.285714-32.914286-29.257143-10.971429-10.971429-18.285714-18.285714-21.942857-25.6 0-14.628571 0-14.628571 3.657143-14.628571z',
            fill: '#FCF7EC'
          })
        ]
    );
  }

  // 自定义节点外观
  getShape() {
    const { model } = this.props;
    const { x, y, width, height, radius } = model;
    const style = model.getNodeStyle();
    return h('g', {style: {
        cursor: 'pointer'
      }}, [
      h('rect', {
        ...style,
        x: x - width / 2, // 矩形默认x，y代表左上角顶点坐标，切换为中心点
        y: y - height / 2,
        rx: radius,
        ry: radius,
        width,
        height,
      }),
      this.getLabelShape(),
    ]);
  }
}

export default {
  type: "between",
  model: BetweenModel,
  view: BetweenView,
};
